package com.ljf.framework.context;

import com.ljf.framework.context.model.LjfRequest;
import com.ljf.framework.context.model.LjfResponse;
import com.ljf.framework.context.model.LjfStorage;


/**
 * 上下文处理器 [ThreadLocal版本]
 *
 * <p>
 * 	使用 [ThreadLocal版本] 上下文处理器需要在全局过滤器或者拦截器内率先调用
 * 	LjfContextForThreadLocalStorage.setBox(req,res, sto) 初始化上下文
 * </p>
 *
 *
 */
public class LjfContextForThreadLocal implements LjfContext {

	@Override
	public LjfRequest getRequest() {
		return LjfContextForThreadLocalStorage.getRequest();
	}

	@Override
	public LjfResponse getResponse() {
		return LjfContextForThreadLocalStorage.getResponse();
	}

	@Override
	public LjfStorage getStorage() {
		return LjfContextForThreadLocalStorage.getStorage();
	}

	@Override
	public boolean matchPath(String pattern, String path) {
		return false;
	}

	@Override
	public boolean isValid() {
		return LjfContextForThreadLocalStorage.getBox() != null;
	}

	@Override
	public void syncContext(Object object) {
		LjfContextForThreadLocalStorage.Box box = (LjfContextForThreadLocalStorage.Box) object;
		LjfContextForThreadLocalStorage.setBox(box.getRequest(),box.getResponse(),box.getStorage());
	}

	@Override
	public Object getSyncObject() {
		return LjfContextForThreadLocalStorage.getBox();
	}

}
